import { DemoDataItem } from '@/models/demo';
import { request } from 'umi';
import type { BaseResult, DataResult, PageResult } from '../dataResult';

export async function get(id: number) {
  return request<DataResult<DemoDataItem>>('/demoapi/get', {
    method: 'GET',
    params: { id },
  });
}

export async function getList(
  params: {
    // query
    pageSize?: number;
    current?: number;
  },
  options?: { [key: string]: any },
) {
  return request<PageResult<DemoDataItem>>('/demoapi/getList', {
    method: 'GET',
    params: { ...params },
    ...(options || {}),
  });
}

export async function addItem(item: DemoDataItem) {
  return request<BaseResult>('/demoapi/add', {
    method: 'POST',
    data: item,
  });
}

export async function updateItem(item: DemoDataItem) {
  return request('/demoapi/update', {
    method: 'POST',
    data: item,
  });
}

export async function deleteItem(id: number) {
  return request('/demoapi/deleteItem ', {
    method: 'POST',
    params: {
      id,
    },
  });
}
